package cn.bdqn.service.impl;

import cn.bdqn.mapper.LostMapper;
import cn.bdqn.pojo.Customer;
import cn.bdqn.pojo.Lost;
import cn.bdqn.service.CustomerService;
import cn.bdqn.service.LostService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class LostServiceImpl implements LostService {
    @Resource
    LostMapper lostMapper;
    @Resource
    CustomerService customerService;
    @Override
    public IPage<Lost> getLostsByPage(String custName, String managerName, String status, Integer pageNo, Integer pageSize) {
        //组装分页条件
        Page<Lost> page=new Page<>(pageNo,pageSize);
        //组装过滤条件 动态sql
        QueryWrapper<Lost> qw=new QueryWrapper();
        qw.like(custName!=null&&!"".equals(custName), "lst_cust_name",custName);
        IPage<Lost> lostIPage = lostMapper.selectPage(page, qw);
        return lostIPage;
    }

    @Override
    public Lost getLost(Long id) {
        return lostMapper.selectById(id);
    }
    @Override
    public void updateLost(Lost cstLost) {
        Lost lost = getLost(cstLost.getLstId());
        Customer customer = customerService.getCustomer(lost.getLstCustNo());
        System.out.println(customer);
        customer.setCustStatus("2");
        customerService.updateCustomer(customer);
        lostMapper.updateById(cstLost);
    }
}
